%{
#include <math.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>

int num_char = 0;	// Number of char in line
int num_line = 1;	// Number line in text

// Using for shifts
int stack[256];		// array with deep value
int stack_num = 0;	// number elements in stack

%}

%option noyywrap
%option never-interactive

%x COMMENT
%x STRING_CONST1
%x STRING_CONST2
%x RAW_STRING_CONST1
%x RAW_STRING_CONST2
%x MULTISTRING_CONST1
%x MULTISTRING_CONST2
%x RAW_MULTISTRING_CONST1
%x RAW_MULTISTRING_CONST2

/* Common definition */
ID				(_+[a-zA-Z0-9]|[a-zA-Z])[a-zA-Z0-9_]*

/* Numeric literals */
/* Integer literals */
NONZERODIGIT 	[1-9]
DIGIT 			[0-9]
OCTDIGIT		[0-7]
BINDIGIT		0|1
HEXDIGIT		{DIGIT}|[a-f]|[A-F]
BININTEGER		0(b|B){BINDIGIT}+
HEXINTEGER		0(x|X){HEXDIGIT}+
OCTINTEGER		0(o|O){OCTDIGIT}+
DECIMALINTEGR	{NONZERODIGIT}{DIGIT}*|0+
INTEGER			{DECIMALINTEGR}|{OCTINTEGER}|{HEXINTEGER}|{BININTEGER}

/* Floating point literals */
FLOATNUMBER		{POINTFLOAT}|{EXPONENTFLOAT}
POINTFLOAT 		{INTPART}?({FRACTION}|({INTPART}\.))
EXPONENTFLOAT 	({INTPART}|{POINTFLOAT}){EXPONENT}
INTPART 		{DIGIT}+
FRACTION		\.{DIGIT}+
EXPONENT		(e|E)[+|\-]?{DIGIT}+

%%

%{
// Local variables
char literal[1024];	// String literal

// Using for shifts
int spaces;			// whitespaces in current line
char buf_str[1024];	// buffering string
int i;				// index
int deep_count;		// Number of deepest
int is_error_dedent = 1;	// Error in shifts
char tmp_str[81];
char str_num[ 5 ];	// 

int integer;		// Integer constant
%}

^[ \t]+			{	
					buf_str[0] = '\0';
					spaces = 0;		// while zero whitespaces in current line
					
					// Definition whitespace count in line
					strcat(buf_str, yytext);					 
					for (i = 0; i < strlen(buf_str); i++)
					{
						if ( buf_str[ i ] == ' ' ) 
						{
							num_char++;
							spaces++;
						}
						
						if ( buf_str[ i ] == '\t' )
						{
							num_char += 4;
							spaces += 4;
						}	
					} // for

					if ( stack_num == 0 )	// first deep-level
					{
						if ( num_line == 1)
						{
							stack[ stack_num ] = spaces;
							stack_num++;							
						}
						else
						{							
							stack[ stack_num++ ] = 0; // zero whitespaces in first line
							stack[ stack_num++ ] = spaces;
							printf("Find IDENT in %d line\n", num_line);
						}
					}										
					else
					{
						if ( spaces > stack[ stack_num - 1] )	// IDENT
						{
							stack[ stack_num++ ] = spaces;
							printf("Find IDENT in %d line\n", num_line);
						}
						
						if ( spaces == stack[ stack_num - 1] )	// Current deep-level
							break;
						
						if ( spaces < stack[ stack_num - 1] )	// DEDENT
						{
							deep_count = 0;
							
							for ( i = stack_num - 2; i >= 0; i-- )
							{
								deep_count++;
								if ( stack[ i ] == spaces )
								{
									is_error_dedent = 0;
									printf("Find %d DEDENT in %d line\n", deep_count, num_line);
									break;
								}
							}
							
							// check for match in stack
							if ( !is_error_dedent )
							{
								for ( i = 1; i <= deep_count; i++)
								{
									stack[ stack_num - i ] = 0;
								}	
								stack_num -= deep_count;				
							}
							else
							{
								printf("Error: Unindent does not match any outher indentation level on %d line\n", num_line);
							}
						}											
					}
				}

{FLOATNUMBER} 	{ printf("A float: \"%f\" ( %d, %d)\n", atof( yytext ), num_line, num_char); num_char += strlen(yytext); }

{BININTEGER}	{
					integer = 0;
					
					for( i = strlen(yytext); i > 2; i-- )
					{
						integer += (yytext[i-1]-'0')*pow(2, strlen(yytext)-i);
					}
					
					printf("An integer: \"%d\" ( %d, %d )\n", integer, num_line, num_char);
					num_char += strlen(yytext);					
				}

{OCTINTEGER}	{
					buf_str[ 0 ] = '\0';
					strcpy( buf_str, yytext + 1 );
					buf_str[0] = '0';
					sscanf( buf_str, "%i", &integer );
					printf("An integer: \"%d\" ( %d, %d )\n", integer, num_line, num_char);
					num_char += strlen(yytext);
				}

{HEXINTEGER}	{										
					sscanf( yytext, "%x", &integer );
					printf("An integer: \"%d\" ( %d, %d )\n", integer, num_line, num_char);
					num_char += strlen(yytext);
				}
		
{DECIMALINTEGR}	{ printf("An integer: \"%d\" ( %d, %d )\n", atoi(yytext), num_line, num_char); num_char += strlen(yytext); }

False			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
class			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
finally			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
is				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
return			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
None			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
continue		{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
for				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
lambda			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
try				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
True			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
def				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
from			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
nonlocal		{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
while			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
and				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
del				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
global			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
not				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
with			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
as				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
elif			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
if				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
or				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
yield			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
assert			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
else			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
import			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
pass			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
break			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
except			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
in				{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
raise			{ printf("A keyword: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }

\+				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
-				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\*				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\*\*			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\/				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\/\/			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\%				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\<\<			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\>\>			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\&				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\|				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\^				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\>				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\<				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\<=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\>=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
==				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
!=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\~				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\+=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
-=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\*=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\/=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\/\/=			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\%=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\&=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\|=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\^=				{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\>\>=			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\<\<=			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\*\*=			{ printf("An operator: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }

\(				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\)				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\[				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\]				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\{				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\}				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
,				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
:				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
\.				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
;				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }
@				{ printf("A delimiter: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }

{ID} 			{ printf("An id: \"%s\" ( %d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }

[ ]+			{ num_char += strlen(yytext); }

[\t]{1}			{ num_char += 4; }

[\n]{1}			{ num_char = 0; num_line++; }

#				{ BEGIN(COMMENT); }
<COMMENT>.*$	{ printf("A comment: \"%s\" (%d,  %d)\n", yytext, num_line, num_char); BEGIN(INITIAL); }

\'									{ strcpy(literal, ""); BEGIN(STRING_CONST1); }
<STRING_CONST1>[^\\\n\']+			{ strcat(literal, yytext); }
<STRING_CONST1,STRING_CONST2,MULTISTRING_CONST1,MULTISTRING_CONST2>\\[0-7]{1,3}			{ 							  
									  strcpy( str_num, yytext );
									  num_to_char( str_num );
									  strcat( literal, str_num );								
									}
<STRING_CONST1,STRING_CONST2,MULTISTRING_CONST1,MULTISTRING_CONST2>\\x[0-9a-fA-F]{1,2}	{ 									  
									  strcpy( str_num, yytext );
									  num_to_char( str_num );
									  strcat( literal, str_num );
									}
<STRING_CONST1,STRING_CONST2>\\n 		{ strcat(literal, "\n"); }
<STRING_CONST1,STRING_CONST2>\\a 		{ strcat(literal, "\a"); }
<STRING_CONST1,STRING_CONST2>\\b 		{ strcat(literal, "\b"); }
<STRING_CONST1,STRING_CONST2>\\f 		{ strcat(literal, "\f"); }
<STRING_CONST1,STRING_CONST2>\\r 		{ strcat(literal, "\r"); }
<STRING_CONST1,STRING_CONST2>\\t		{ strcat(literal, "\t"); }
<STRING_CONST1,STRING_CONST2>\\v 		{ strcat(literal, "\v"); }
<STRING_CONST1,STRING_CONST2>\\\n
<STRING_CONST1,STRING_CONST2>\\\\ 		{ strcat(literal, "\\"); }
<STRING_CONST1>\\\' 					{ strcat(literal, "\'"); }
<STRING_CONST1>\'						{ printf("A string literal: \"%s\"( %d, %d )\n", literal, num_line, num_char);
											num_char += strlen(literal);
											BEGIN(INITIAL); }

\"									{ strcpy(literal, ""); BEGIN(STRING_CONST2); }
<STRING_CONST2>[^\\\n\"]+ 			{ strcat(literal, yytext); }
<STRING_CONST2>\\\" 				{ strcat(literal, "\""); }
<STRING_CONST2>\"					{ printf("A string literal: \"%s\" (%d, %d )\n", literal, num_line, num_char);
										num_char += strlen(literal);
										BEGIN(INITIAL); }

(r|R)\'										{ strcpy(literal, ""); BEGIN(RAW_STRING_CONST1); }
<RAW_STRING_CONST1>[^\\\n\']+				{ strcat(literal, yytext); }
<RAW_STRING_CONST1,RAW_STRING_CONST2>\\\n 	{ strcat(literal, "\\\n"); }
<RAW_STRING_CONST1,RAW_STRING_CONST2>\\ 	{ strcat(literal, "\\"); }
<RAW_STRING_CONST1>\'						{ printf("A escaped string literal: \"%s\" ( %d, %d )\n", literal, num_line, num_char); 
												num_char += strlen(literal); 
												BEGIN(INITIAL); }

(r|R)\"							{ strcpy(literal, ""); BEGIN(RAW_STRING_CONST2); }
<RAW_STRING_CONST2>[^\\\n\"]+ 	{ strcat(literal, yytext); }
<RAW_STRING_CONST2>\"			{ printf("A escaped string literal: \"%s\"( %d, %d)\n", literal, num_line, num_char);
									num_char += strlen(literal);
									BEGIN(INITIAL); }

\'\'\'							{ strcpy(literal, ""); BEGIN(MULTISTRING_CONST1); }
<MULTISTRING_CONST1>[^\\\']+	{ strcat(literal, yytext); }
<MULTISTRING_CONST1>\\n 		{ strcat(literal, "\n");   }
<MULTISTRING_CONST1>\\\n
<MULTISTRING_CONST1>\\\\		{ strcat(literal, "\\");   }
<MULTISTRING_CONST1>\\\"		{ strcat(literal, "\"");   }
<MULTISTRING_CONST1>\\. 		{ strcat(literal, yytext); }
<MULTISTRING_CONST1>\'{1,2} 	{ strcat(literal, yytext); }
<MULTISTRING_CONST1>\'{3}		{ printf("A multiline string literal: \"%s\" ( %d, %d)\n", literal, num_line, num_char);
									num_char += strlen(literal);
									BEGIN(INITIAL); }

\"\"\"							{ strcpy(literal, ""); BEGIN(MULTISTRING_CONST2); }
<MULTISTRING_CONST2>[^\\\"]+ 	{ strcat(literal, yytext); }
<MULTISTRING_CONST2>\\n 		{ strcat(literal, "\n");   }
<MULTISTRING_CONST2>\\\n
<MULTISTRING_CONST2>\\\\		{ strcat(literal, "\\");   }
<MULTISTRING_CONST2>\\\"		{ strcat(literal, "\"");   }
<MULTISTRING_CONST2>\\. 		{ strcat(literal, yytext); }
<MULTISTRING_CONST2>\"{1,2} 	{ strcat(literal, yytext); }
<MULTISTRING_CONST2>\"{3}		{ printf("A multiline string literal: \"%s\" ( %d, %d)\n", literal, num_line, num_char);
									num_char += strlen(literal);
									BEGIN(INITIAL); }

(r|R)\'\'\'							{ strcpy(literal, ""); BEGIN(RAW_MULTISTRING_CONST1); }
<RAW_MULTISTRING_CONST1>[^\\\']+ 	{ strcat(literal, yytext); }
<RAW_MULTISTRING_CONST1>\\\n 		{ strcat(literal, "\\\n"); }
<RAW_MULTISTRING_CONST1>\\ 			{ strcat(literal, "\\"); }
<RAW_MULTISTRING_CONST1>\'{1,2} 	{ strcat(literal, yytext); }
<RAW_MULTISTRING_CONST1>\'{3}		{ printf("An escaped multiline string literal: \"%s\" ( %d, %d )\n", literal, num_line, num_char);
										num_char += strlen(literal);
										BEGIN(INITIAL); }

(r|R)\"\"\"							{ strcpy(literal, ""); BEGIN(RAW_MULTISTRING_CONST2); }
<RAW_MULTISTRING_CONST2>[^\\\"]+ 	{ strcat(literal, yytext); }
<RAW_MULTISTRING_CONST2>\\\n 		{ strcat(literal, "\\\n"); }
<RAW_MULTISTRING_CONST2>\\	 		{ strcat(literal, "\\"); }
<RAW_MULTISTRING_CONST2>\"{1,2} 	{ strcat(literal, yytext); }
<RAW_MULTISTRING_CONST2>\"{3}		{ printf("An escaped multiline string literal: \"%s\" ( %d, %d )\n", literal, num_line, num_char);
										num_char += strlen(literal);
										BEGIN(INITIAL); }

.	{ printf( "Unrecognized character: \"%s\" (%d, %d )\n", yytext, num_line, num_char); num_char += strlen(yytext); }

%%
FILE * create_tmp_file( FILE * file ); // Add one whitespace in start each line
int num_to_char( char * str );

void main( int argc, char ** argv )
{
	FILE * input_file;
	++argv, --argc;  /* skip over program name */
	
	if ( argc > 0 )
		input_file = fopen( argv[0], "r" );
	else
		input_file = stdin;
	
	yyin = create_tmp_file( input_file );
	
	yylex();
	_getch();	// Delay
	
	// Close input file
	if ( input_file )
		if ( fclose( input_file ) )
			printf( "Could'n close %s file", argv[ 0 ] );
	
	_getch();	// Delay
}

// -----------------[ User Functions ]-----------------
// Add one whitespase to start line
FILE * create_tmp_file( FILE * input_file )
{
	FILE * tmp_file;
	int rand_num;
	char  tmp_fname[65];
	char  str[256];
	char result_str[256];
	int is_empty_string;	// check for string only whitespaces
	int i;
	
	// Initialize random number generator
	srand( (unsigned)time( NULL ) );
	rand_num = rand();
	
	itoa( rand_num, tmp_fname, 10 );
	strcat( tmp_fname, ".txt" );
	
	// Create temporary file, when will be delete in end of program
	if ( (tmp_file = fopen( tmp_fname, "a+tD" )) == NULL )
		printf("Could'n open %s file\n", tmp_fname);
	
	while ( ! feof( input_file ) )
	{
		is_empty_string = 1;		// string consist only whitespaces
		result_str[ 0 ] = '\0';
		strcat( result_str, " " );
		
		fgets( str, 1024, input_file );
				
		// Check for empty string
		i = 0;
		while ( str[ i ] )	
		{
			if ( str[ i ] != ' ' && str[ i ] != '\t' && str[ i ] != '\n' )
			{
				is_empty_string = 0;
				break;	
			}
			i++;
		}
		if ( ! is_empty_string )
		{
			strcat( result_str, str );
		}
		else
		{
			result_str[ 0 ] = '\n';
			result_str[ 1 ] = '\0';
		}
		
		fputs( result_str, tmp_file );
	}
	
	fseek( tmp_file, 0, SEEK_SET );
	
	return tmp_file;	
}

//
int num_to_char( char * str )
{
	char * buf = (char *)malloc( 5 );
	int integer;
	
	strcpy( buf, str );
	buf [ 0 ] = '0';
	sscanf( buf, "%i", &integer );
	
	buf[ 0 ] = (char)integer;
	buf[ 1 ] = '\0';
	
	strcpy( str, buf );
	
	free( buf );
	return 1;
}